package com.yic.module.base.dal.mysql.center;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.base.dal.dataobject.center.CenterDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.base.controller.admin.center.vo.*;

/**
 * 工作中心 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface CenterMapper extends BaseMapperX<CenterDO> {

    default PageResult<CenterDO> selectPage(CenterPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CenterDO>()
                .likeIfPresent(CenterDO::getName, reqVO.getName())
                .eqIfPresent(CenterDO::getCode, reqVO.getCode())
                .eqIfPresent(CenterDO::getStatus, reqVO.getStatus())
                .eqIfPresent(CenterDO::getFactoryId, reqVO.getFactoryId())
                .orderByDesc(CenterDO::getId));
    }

    default List<CenterDO> selectList(CenterExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CenterDO>()
                .likeIfPresent(CenterDO::getName, reqVO.getName())
                .eqIfPresent(CenterDO::getCode, reqVO.getCode())
                .eqIfPresent(CenterDO::getStatus, reqVO.getStatus())
                .eqIfPresent(CenterDO::getFactoryId, reqVO.getFactoryId())
                .orderByDesc(CenterDO::getId));
    }

    default List<CenterDO> selectList(Collection<Long> ids, Collection<Integer> statuses) {
        return selectList(new LambdaQueryWrapperX<CenterDO>()
                .inIfPresent(CenterDO::getId, ids)
                .inIfPresent(CenterDO::getStatus, statuses));
    }

    default CenterDO selectByName(String name) {
        return selectOne(new LambdaQueryWrapperX<CenterDO>()
                .eq(CenterDO::getName, name));
    }

    default CenterDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<CenterDO>()
                .eq(CenterDO::getCode, code));
    }
}
